package cn.zxl.graduate.web.advice;

import cn.zxl.graduate.exception.BusinessException;
import cn.zxl.graduate.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: bo-feifei
 * @Date 2021/11/1 15:33
 * @Version 1.0
 */
@Slf4j
@RestControllerAdvice
public class WebControllerAdvice {

    @ExceptionHandler(BusinessException.class)
    public JsonResult<?> busException(BusinessException ex) {
        return JsonResult.error(JsonResult.CODE_ERROR_PARAM,ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public JsonResult<?> exception(Exception e) {
        log.error(e.getMessage());
        return JsonResult.error(JsonResult.CODE_ERROR,JsonResult.MSG_ERROR);
    }
}
